using System;
using System.Collections.Generic;
using System.Linq;
namespace WebClient.Models.Repositories
{
	#region using
	using WebClient.Helpers;
	using WebClient.Models.ViewModels;
	using WebClient.Models;
    using WebClient.CF_DAL_WS;
	#endregion
	public class CartRepository
	{
		public List<CartDTO> SelectByCartID(string cartid)
		{
			try
			{
                return DALService.Instance.Cart_SelectByCartID(cartid).ToList();
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
			}
            return null;
		}

        public CartDTO SelectByRecordID(string recordid)
        {
            try
            {
                return DALService.Instance.Cart_SelectByRecordID(recordid);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
                else
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
            }
            return null;
        }

        public CartDTO SelectByIDAndRecordID(string cartid, string recordid)
        {
            try
            {
                return DALService.Instance.Cart_SelectByIDAndRecordID(cartid, recordid);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
                else
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
            }
            return null;
        }

        public CartDTO SelectByIDAndFood(string cartid, string foodid)
        {
            try
            {
                return DALService.Instance.Cart_SelectByIDAndFood(cartid, foodid);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
                else
                    GlobalVariables.Logger.Error("Cart - SelectByID: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
            }
            return null;
        }

		public bool Insert(CartDTO obj)
		{
			try
			{
                return DALService.Instance.Cart_Insert(obj);
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					GlobalVariables.Logger.Error("Cart - Insert: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					GlobalVariables.Logger.Error("Cart - Insert: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
			}
            return false;
		}

		public bool Delete(string cartid, string recordid)
		{
			try
			{
                return DALService.Instance.Cart_Delete(cartid, recordid);
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					GlobalVariables.Logger.Error("Cart - Delete: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					GlobalVariables.Logger.Error("Cart - Delete: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
			}
            return false;
		}

        public bool Empty(string cartid)
        {
            try
            {
                return DALService.Instance.Cart_Empty(cartid);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    GlobalVariables.Logger.Error("Cart - Empty: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
                else
                    GlobalVariables.Logger.Error("Cart - Empty: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
            }
            return false;
        }

		public bool Update(CartDTO obj)
		{
            try
            {
                return DALService.Instance.Cart_Update(obj);
            }
            catch
            {
                return false;
            }
		}
	}
}